<template>
    <div class="zhflBox">
        <div class="zhflTitle">展会分类</div>
        <div class="zhflCardFlex">
            <div class="zhflCardFor" v-for="(item, index) in DWTypeGroupByData" :key="index"
                @click="listJumpfun({type2:item.value})">
                {{ item.text }}({{ item.sum }})
            </div>
        </div>
    </div>
    <div class="BlackTitleMargin">
        <BlackTitleSlot title="推荐展会" :showMore="true" @more-click="listJumpfun({type:'推荐展会'})">
            <template #nr>
                <div class="flexGap">
                    <ExhibitionListCard class="listCardBox" v-for="(item, index) in tjzhlcExhibitionsInfosDWLoadData" :key="index"
                        :exhibition="item" />
                </div>
            </template>
        </BlackTitleSlot>
    </div>
    <div class="BlackTitleMargin">
        <BlackTitleSlot title="最新展会" :showMore="true" @more-click="listJumpfun({type:'最新展会'})">
            <template #nr>
                <div class="flexGap">
                    <ExhibitionListCard class="listCardBox" v-for="(item, index) in zxzhlcExhibitionsInfosDWLoadData" :key="index"
                        :exhibition="item" />
                </div>
            </template>
        </BlackTitleSlot>
    </div>
    <div class="BlackTitleMargin">
        <BlackTitleSlot title="全部展会" :showMore="true" @more-click="listJumpfun({type:'全部展会'})">
            <template #nr>
                <div class="flexGap">
                    <ExhibitionListCard class="listCardBox" v-for="(item, index) in qbzhlcExhibitionsInfosDWLoadData" :key="index"
                        :exhibition="item" />
                </div>
            </template>
        </BlackTitleSlot>
    </div>
</template>
<script setup>
import BlackTitleSlot from '@/components/general/BlackTitleSlot.vue';
import ExhibitionListCard from '@/components/general/ExhibitionListCard.vue';
import { DWTypeGroupBy } from '@/api/dictionary.js';
import { lcExhibitionsInfosDWLoad } from '@/api/api.js'
import { ref, onMounted } from 'vue';
import { useRouter } from 'vue-router';
const router = useRouter();
onMounted(() => {
    DWTypeGroupByfun()
    lcExhibitionsInfosDWLoadfun('推荐展会')
    lcExhibitionsInfosDWLoadfun('最新展会')
    lcExhibitionsInfosDWLoadfun('全部展会')
})
const DWTypeGroupByData = ref([])
// 展会类型
const DWTypeGroupByfun = async () => {
    const res = await DWTypeGroupBy();
    DWTypeGroupByData.value = Object.entries(res.result).map(([key, value]) => ({
        text: key,
        value: key,
        sum: value
    }));
}
const parameterData = ref({
    pageNum: 1, // 当前页码
    pageSize: 10, // 每页显示的条数
    type:'',
})
const tjzhlcExhibitionsInfosDWLoadData = ref([]) // 推荐展会列表数据
const zxzhlcExhibitionsInfosDWLoadData = ref([]) // 最新展会列表数据
const qbzhlcExhibitionsInfosDWLoadData = ref([]) // 全部展会列表数据
// 展会列表接口
const lcExhibitionsInfosDWLoadfun = async (type) => {
    parameterData.value.type = type
    const res = await lcExhibitionsInfosDWLoad(parameterData.value);
    if (type === '推荐展会') {
        tjzhlcExhibitionsInfosDWLoadData.value = res.result;
    }
    if (type === '最新展会') {
        zxzhlcExhibitionsInfosDWLoadData.value = res.result;
    }
    if (type === '全部展会') {
        qbzhlcExhibitionsInfosDWLoadData.value = res.result;
    }
}

// 列表跳转
const listJumpfun = (data) => {
    router.push({
        path: '/ExhibitionList',
        query: {
            ...data
        }
    });
}
</script>
<style scoped lang="scss">
.zhflBox {
    width: 100%;
    height: 100%;

    .zhflTitle {
        font-size: 24px;
        color: #1F1F1F;
    }

    .zhflCardFlex {
        margin-top: 30px;
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 20px;


        .zhflCardFor {
            // width: 20%;
            // width: 220px;
            flex: 1;
            background: #fff;
            border-radius: 8px;
            padding: 30px 20px;
            font-weight: 300;
            font-size: 16px;
            text-align: center;
            color: #1F1F1F;
            box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1),
                0 8px 16px rgba(0, 0, 0, 0.1);
            cursor: pointer;
        }
    }
}

.BlackTitleMargin {
    margin-top: 40px;
}

.flexGap {
    display: flex;
    gap: 20px;
    flex-wrap: wrap;

    .listCardBox {
        width: calc(20% - 16px); // 5列布局（100% / 5 = 20%）
        flex-shrink: 0;
    }
}
</style>